using ERP.Inventory.Api.Read.Application.Command.台账;
using ERP.Inventory.Api.Read.DTO;
using ERP.Inventory.Domain.库存管理;
using ERP.Inventory.Errorcode;
using ERP.Inventory.Infastructure.Interface;
using MediatR;
using System.Security.Cryptography.X509Certificates;

namespace ERP.Inventory.Api.Read.Application.Handler.台账
{
//    public class ShopandStoreHandler : IRequestHandler<ShopandStoreCommand, ApiPaging<ShopandStoreDTO>>
//    {
//        private readonly IBaseRepository<ShopModel> shopRepo;
//        private readonly IBaseRepository<StoreModel> storeRepo;

//        public ShopandStoreHandler(IBaseRepository<ShopModel> shopRepo, IBaseRepository<StoreModel> storeRepo)
//        {
//            this.shopRepo = shopRepo;
//            this.storeRepo = storeRepo;
//        }

//        public Task<ApiPaging<ShopandStoreDTO>> Handle(ShopandStoreCommand request, CancellationToken cancellationToken)
//        {
//            var res = new ApiPaging<ShopandStoreDTO>();
//            var shop = shopRepo.GetAll().Where(x => x.IsDel == false);
//            var store = storeRepo.GetAll().Where(x => x.IsDel == false);
//            var linq = from a in shop
//                       join b in store on a.StoreId equals b.Id
//                       select new ShopandStoreDTO
//                       {
// Id           =a.Id            ,
//ShopName      =a.ShopName      ,
//ShopCode      =a.ShopCode      ,
//ShopGui       =a.ShopGui       ,
//ShopUnit      =a.ShopUnit      ,
//SystemNum     =a.SystemNum     ,
//ActualNum     =a.ActualNum     ,
//DifferentCount=a.DifferentCount,
//StoreName     =b.StoreName     ,

//                       };
//            if (!string.IsNullOrEmpty(request.ShopName))
//            {
//                linq = linq.Where(x => x.ShopName.Contains(request.ShopName));
//            }
//            if (!string.IsNullOrEmpty(request.StoreName))
//            {
//                linq = linq.Where(x => x.StoreName.Contains(request.StoreName));
//            }
//            if (!string.IsNullOrEmpty(request.ShopUnit))
//            {
//                linq = linq.Where(x => x.ShopUnit.Contains(request.ShopUnit));
//            }
//            var totalcount = linq.Count();
//            var totalpage = (int)Math.Ceiling(totalcount * 1.0 / request.PageSize);
//            linq = linq.OrderByDescending(x => x.Id).Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize);
//            res.totalcount = totalcount;
//            res.totalpage = totalpage;
//            res.Message = "显示成功";
//            res.Data = linq.ToList();
//            res.Code = ApiEnum.Ok;
//            return Task.FromResult(res);
//        }
//    }
}
